<html>
<head>
    <meta charset="UTF-8">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@yield('title') - {{env('APP_NAME')}}</title>
    <link rel="shortcut icon" href="{{cdn('/assets/img/logo-2.png')}}" type="image/x-icon">
    <link rel="stylesheet" href="{{cdn('/assets/css/bootstrap/bootstrap.min.css')}}">
    <link rel="stylesheet" href="{{cdn('/assets/css/font-awesome.min.css')}}">
</head>
<body>
    @include('include.alert')
    <div style="width: 90%;margin: 30px 5% 10px 5%; ">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>ID</th>
                <th>显示名称</th>
                <th>字体颜色</th>
                <th>启用?</th>
                <th>排序</th>
                <th>创建日期</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @if (!empty($partitionCategorie))
                @foreach($partitionCategorie as $item)
                    <tr>
                        <td>{{$item->categorie->id or 0}}</td>
                        <td>{{$item->categorie->name or ''}}</td>
                        <td style="color:{{$item->categorie->color or ''}}">{{$item->categorie->color or ''}}</td>
                        <td>
                            @if ($item->categorie->is_enable == 1)
                                <i class="fa fa-check text-success"></i>
                            @else
                                <i class="fa fa-times text-danger"></i>
                            @endif
                        </td>
                        <td>{{$item->categorie->index or 0}}</td>
                        <td title="{{$item->categorie->created_at}}">{{dateTimeC($item->categorie->created_at)}}前</td>
                        <td>
                            <a class="btn btn-success" target="_blank" href="{{url('/admin/plate/tags')}}"><i class="fa fa-edit"></i>&nbsp;编辑</a>
                            <button class="btn btn-sm btn-danger" onclick="deletePalatTag('{{$item->id or 0}}', this)"><i class="fa fa-trash"></i>&nbsp;删除</button>
                        </td>
                    </tr>
                @endforeach
            @endif
            </tbody>
        </table>
    </div>
    <div style="width: 50%;margin: 10px 25% 10px 25%;">
        <form action="{{url('/admin/plate/tag/add')}}"  method="post" class="form-horizontal">
            {{csrf_field()}}
            <input type="hidden" name="plate_id" value="{{$plate_id or 0}}">
            <div class="form-group">
                <label for="select_tag" class="control-label text-success">类型名称</label>
                <select id="select_tag" class="form-control" name="id">
                    @if (!empty($categorie))
                        <option disabled value="0" selected>请选择</option>
                        @foreach($categorie as $c)
                            <option value="{{$c->id or 0}}" data-color="{{$c->color or '#000'}}">{{$c->name or ''}}</option>
                        @endforeach
                    @else
                        <option disabled value="=0">没有数据</option>
                    @endif
                </select>
                <div class="form-group" style="margin-top: 10px; margin-left: 5px">
                    <button type="submit" class="btn btn-success">添加</button>
                </div>
            </div>
        </form>
    </div>
    <script src="{{cdn('/supervise/assets/js/jquery-1.10.2.min.js')}}"></script>
    <script src="{{cdn('/supervise/assets/js/jqueryui-1.10.3.min.js')}}"></script>
    <script src="{{cdn('/supervise/assets/js/bootstrap.min.js')}}"></script>
    <script>
        $(document).ready(function () {
            $('#select_tag').change(function () {
                $op = $(this).children('option:selected');
                $color = $op.attr('data-color');
                $(this).css('color', $color);
            });
        })
        function deletePalatTag($id, $this) {
            $.post('{{url('/admin/plate/tag/del')}}',{
                _token:$('meta[name="csrf-token"]').attr('content'),
                id:$id
            }, function (data) {
                if (data.code == 0){
                    $($this).parents('tr').remove();
                }else{
                    alert('Error:'+data.code +' msg:'+data.msg);
                }
            })
        }
    </script>
</body>
</html>